home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / plymouth-set-default-theme < prev    next >
Encoding:
Text File  |  2012-07-27  |  5.6 KB  |  186 lines

  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. [ -z "$PLYMOUTH_LIBEXECDIR" ] && PLYMOUTH_LIBEXECDIR="/usr/lib/plymouth"
  6. [ -z "$PLYMOUTH_DATADIR" ] && PLYMOUTH_DATADIR="/usr/share"
  7. [ -z "$PLYMOUTH_CONFDIR" ] && PLYMOUTH_CONFDIR="/etc/plymouth/"
  8. [ -z "$PLYMOUTH_POLICYDIR" ] && PLYMOUTH_POLICYDIR="/usr/share/plymouth/"
  9. if [ -z "$PLYMOUTH_PLUGIN_PATH" ]; then
  10.     if [ -z "$LIB" ]; then
  11.         PLYMOUTH_PLUGIN_PATH="$(plymouth --get-splash-plugin-path)"
  12.     else
  13.         [ -z "$PLYMOUTH_LIBDIR" ] && PLYMOUTH_LIBDIR="/usr/lib"
  14.         PLYMOUTH_PLUGIN_PATH=${PLYMOUTH_LIBDIR}/plymouth/
  15.     fi
  16. fi
  17.  
  18. function usage ()
  19. {
  20.   echo "usage: plymouth-set-default-theme { --list | --reset | <theme-name> [ --rebuild-initrd ] | --help }"
  21. }
  22.  
  23. function show_help() {
  24.   cat <<EOF
  25. Plymouth theme chooser
  26. $(usage)
  27.  
  28.   -h, --help             Show this help message
  29.   -l, --list             Show available themes
  30.   -r. --reset            Reset to default theme
  31.   -R, --rebuild-initrd   Rebuild initrd (necessary after changing theme)
  32.   <theme-name>           Name of new theme to use (see --list for available themes)
  33.  
  34. EOF
  35. }
  36.  
  37. function list_themes ()
  38. {
  39.         for theme in ${PLYMOUTH_DATADIR}/plymouth/themes/*/*.plymouth; do
  40.                 [ -f $theme ] || continue;
  41.                 echo "$(basename $theme .plymouth)"
  42.         done
  43. }
  44.  
  45. function read_theme_name_from_file ()
  46. {
  47.         echo $(grep -v '^#' $1 2> /dev/null |
  48.         awk -F= '/Theme=/ { print $2 }')
  49. }
  50.  
  51. function get_default_theme ()
  52. {
  53.         THEME_NAME=$(read_theme_name_from_file ${PLYMOUTH_CONFDIR}/plymouthd.conf)
  54.         if [ -z "$THEME_NAME" -o ! -r "${PLYMOUTH_DATADIR}/plymouth/themes/$THEME_NAME/$THEME_NAME.plymouth" ]; then
  55.                 THEME_NAME=$(read_theme_name_from_file ${PLYMOUTH_POLICYDIR}/plymouthd.defaults)
  56.         fi
  57.  
  58.         if [ -z "$THEME_NAME" -o ! -r "${PLYMOUTH_DATADIR}/plymouth/themes/$THEME_NAME/$THEME_NAME.plymouth" ]; then
  59.                 THEME_NAME=$(basename $(readlink ${PLYMOUTH_DATADIR}/plymouth/themes/default.plymouth) .plymouth)
  60.         fi
  61.         [ -z "$THEME_NAME" ] || echo $THEME_NAME && exit 1
  62. }
  63.  
  64. DO_RESET=0
  65. DO_INITRD_REBUILD=0
  66. DO_LIST=0
  67. DO_HELP=0
  68. THEME_NAME=""
  69. while [ $# -gt 0 ]; do
  70.         case "$1" in
  71.  
  72.         -l|--list)
  73.                 if [ -n "$THEME_NAME" ]; then
  74.                         echo "You can only specify --list or a theme name, not both" >&2
  75.                         echo $(usage) >&2
  76.                         exit 1
  77.                 fi
  78.  
  79.                 if [ $DO_RESET -ne 0 ]; then
  80.                         echo "You can only specify --reset or --list, not both" >&2
  81.                         echo $(usage) >&2
  82.                         exit 1
  83.                 fi
  84.  
  85.                 DO_LIST=1
  86.         ;;
  87.  
  88.         -R|--rebuild-initrd)
  89.                 DO_INITRD_REBUILD=1
  90.         ;;
  91.  
  92.         -r|--reset|default)
  93.                 if [ -n "$THEME_NAME" ]; then
  94.                         echo "You can only specify --reset or a theme name, not both" >&2
  95.                         echo $(usage) >&2
  96.                         exit 1
  97.                 fi
  98.  
  99.                 if [ $DO_LIST -ne 0 ]; then
  100.                         echo "You can only specify --reset or --list, not both" >&2
  101.                         echo $(usage) >&2
  102.                         exit 1
  103.                 fi
  104.  
  105.                 DO_RESET=1
  106.         ;;
  107.  
  108.         -h|--help)
  109.                 DO_HELP=1
  110.         ;;
  111.  
  112.         *)
  113.                 if [ -n "$THEME_NAME" ]; then
  114.                         echo "You can only specify one theme at a time" >&2
  115.                         echo $(usage) >&2
  116.                         exit 1
  117.                 fi
  118.  
  119.                 if [ $DO_RESET -ne 0 ]; then
  120.                         echo "You can only specify --reset or a theme name, not both" >&2
  121.                         echo $(usage) >&2
  122.                         exit 1
  123.                 fi
  124.  
  125.                 if [ $DO_LIST -ne 0 ]; then
  126.                         echo "You can only specify --list or a theme name, not both" >&2
  127.                         echo $(usage) >&2
  128.                         exit 1
  129.                 fi
  130.  
  131.                 THEME_NAME="$1"
  132.         ;;
  133.   esac
  134.   shift
  135. done
  136.  
  137. if [ $DO_HELP -eq 1 ]; then
  138.         show_help
  139.         exit $?
  140. fi
  141.  
  142. if [ $DO_LIST -ne 0 ]; then
  143.         list_themes
  144.         exit $?
  145. fi
  146.  
  147. if [ $DO_RESET -eq 0 ] && [ $DO_INITRD_REBUILD -eq 0 ] && [ -z $THEME_NAME ]; then
  148.         get_default_theme
  149.         exit $?
  150. fi
  151.  
  152. if [ `id -u` -ne 0 ]; then
  153.         echo "This program must be run as root" >&2
  154.         exit 1
  155. fi
  156.  
  157. if [ $DO_RESET -ne 0 ]; then
  158.         [ -f ${PLYMOUTH_CONFDIR}/plymouthd.conf ] || exit 0
  159.         sed -i -e '/^Theme[[:blank:]]*=.*/d' ${PLYMOUTH_CONFDIR}/plymouthd.conf
  160.         exit $?
  161. fi
  162.  
  163. if [ ! -e ${PLYMOUTH_DATADIR}/plymouth/themes/${THEME_NAME}/${THEME_NAME}.plymouth ]; then
  164.         echo "${PLYMOUTH_DATADIR}/plymouth/themes/${THEME_NAME}/${THEME_NAME}.plymouth does not exist" >&2
  165.         exit 1
  166. fi
  167.  
  168. MODULE_NAME=$(grep "ModuleName *= *" ${PLYMOUTH_DATADIR}/plymouth/themes/${THEME_NAME}/${THEME_NAME}.plymouth | sed 's/ModuleName *= *//')
  169.  
  170. if [ ! -e ${PLYMOUTH_PLUGIN_PATH}${MODULE_NAME}.so ]; then
  171.         echo "${PLYMOUTH_PLUGIN_PATH}${MODULE_NAME}.so does not exist" >&2
  172.         exit 1
  173. fi
  174.  
  175. [ -L ${PLYMOUTH_DATADIR}/plymouth/themes/default.plymouth ] && rm -f ${PLYMOUTH_DATADIR}/plymouth/themes/default.plymouth
  176.  
  177. [ -d ${PLYMOUTH_CONFDIR} ] || mkdir -p ${PLYMOUTH_CONFDIR}
  178. grep -q '^[[]Daemon[]]' ${PLYMOUTH_CONFDIR}/plymouthd.conf 2> /null || echo '[Daemon]' >> ${PLYMOUTH_CONFDIR}/plymouthd.conf
  179. sed -i -e '/^Theme[[:blank:]]*=.*/d' ${PLYMOUTH_CONFDIR}/plymouthd.conf
  180. sed -i -e "s/^\([[]Daemon[]]\)\n*/\1\nTheme=${THEME_NAME}/" ${PLYMOUTH_CONFDIR}/plymouthd.conf
  181.  
  182. if [ $DO_INITRD_REBUILD -ne 0 ] ; then
  183.         (${PLYMOUTH_LIBEXECDIR}/plymouth/plymouth-update-initrd)
  184. fi
  185.  
  186.